package com.yiwei.jmx.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.view.ViewGroup;
import android.widget.FrameLayout;
import android.widget.TextView;


import com.yiwei.jmx.R;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;


/**
 * Created by xsooy-pc on 2017/10/23.
 */

public class TabTopAdapter extends ItemAdapter<String, TabTopAdapter.DefaultHolder> {


    private int selectPoi = 0;

    public TabTopAdapter(Context context) {
        super(context);
    }

    @Override
    public DefaultHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        return new DefaultHolder(inflate(R.layout.item_tab_top, parent));
    }

    @Override
    public void onBindViewHolder(DefaultHolder holder, int position) {
        String title = getItem(position);
        holder.poi = position;
        if (selectPoi == position) {
            holder.txtTitle.setTextColor(0xff4C81FF);
//            holder.txtTitle.setTypeface(Typeface.defaultFromStyle(Typeface.BOLD));
            holder.viewSign.setVisibility(View.VISIBLE);
        } else {
            holder.txtTitle.setTextColor(0xff616185);
//            holder.txtTitle.setTypeface(Typeface.defaultFromStyle(Typeface.NORMAL));
            holder.viewSign.setVisibility(View.GONE);
        }
        holder.txtTitle.setText(title);
    }

    public void setSelectPoi(int selectPoi) {
        this.selectPoi = selectPoi;
        notifyDataSetChanged();
    }

    class DefaultHolder extends RecyclerView.ViewHolder {
        @BindView(R.id.txt_title)
        TextView txtTitle;
        @BindView(R.id.view_sign)
        View viewSign;
        @BindView(R.id.layout_total)
        FrameLayout layoutTotal;
        int poi;

        @OnClick(R.id.layout_total)
        public void onViewClicked() {
            selectPoi = poi;
            notifyDataSetChanged();
            if (onChooseListener != null) {
                onChooseListener.onClick(selectPoi);
            }
        }

        public DefaultHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }
    }


    private OnChooseListener onChooseListener;

    public void setOnChooseListener(OnChooseListener onChooseListener) {
        this.onChooseListener = onChooseListener;
    }

    public interface OnChooseListener {
        void onClick(int poi);
    }
}
